1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module sourceview.Region; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import glib.Str; 30 private import glib.c.functions; 31 private import gobject.ObjectG; 32 private import gtk.TextBuffer; 33 private import gtk.TextIter; 34 private import sourceview.RegionIter; 35 private import sourceview.c.functions; 36 public import sourceview.c.types; 37 38 39 /** 40 * Region utility. 41 * 42 * A `GtkSourceRegion` permits to store a group of subregions of a 43 * [class@Gtk.TextBuffer]. `GtkSourceRegion` stores the subregions with pairs of 44 * [class@Gtk.TextMark]'s, so the region is still valid after insertions and deletions 45 * in the [class@Gtk.TextBuffer]. 46 * 47 * The [class@Gtk.TextMark] for the start of a subregion has a left gravity, while the 48 * [class@Gtk.TextMark] for the end of a subregion has a right gravity. 49 * 50 * The typical use-case of `GtkSourceRegion` is to scan a [class@Gtk.TextBuffer] chunk by 51 * chunk, not the whole buffer at once to not block the user interface. The 52 * `GtkSourceRegion` represents in that case the remaining region to scan. You 53 * can listen to the [signal@Gtk.TextBuffer::insert-text] and 54 * [signal@Gtk.TextBuffer::delete-range] signals to update the `GtkSourceRegion` 55 * accordingly. 56 * 57 * To iterate through the subregions, you need to use a [struct@RegionIter], 58 * for example: 59 * ```c 60 * GtkSourceRegion *region; 61 * GtkSourceRegionIter region_iter; 62 * 63 * gtk_source_region_get_start_region_iter (region, ®ion_iter); 64 * 65 * while (!gtk_source_region_iter_is_end (®ion_iter)) 66 * { 67 * GtkTextIter subregion_start; 68 * GtkTextIter subregion_end; 69 * 70 * if (!gtk_source_region_iter_get_subregion (®ion_iter, 71 * &subregion_start, 72 * &subregion_end)) 73 * { 74 * break; 75 * } 76 * 77 * // Do something useful with the subregion. 78 * 79 * gtk_source_region_iter_next (®ion_iter); 80 * } 81 * ``` 82 */ 83 public class Region : ObjectG 84 { 85 /** the main Gtk struct */ 86 protected GtkSourceRegion* gtkSourceRegion; 87 88 /** Get the main Gtk struct */ 89 public GtkSourceRegion* getRegionStruct(bool transferOwnership = false) 90 { 91 if (transferOwnership) 92 ownedRef = false; 93 return gtkSourceRegion; 94 } 95 96 /** the main Gtk struct as a void* */ 97 protected override void* getStruct() 98 { 99 return cast(void*)gtkSourceRegion; 100 } 101 102 /** 103 * Sets our main struct and passes it to the parent class. 104 */ 105 public this (GtkSourceRegion* gtkSourceRegion, bool ownedRef = false) 106 { 107 this.gtkSourceRegion = gtkSourceRegion; 108 super(cast(GObject*)gtkSourceRegion, ownedRef); 109 } 110 111 112 /** */ 113 public static GType getType() 114 { 115 return gtk_source_region_get_type(); 116 } 117 118 /** 119 * 120 * Params: 121 * buffer = a #GtkTextBuffer. 122 * Returns: a new #GtkSourceRegion object for @buffer. 123 * 124 * Throws: ConstructionException GTK+ fails to create the object. 125 */ 126 public this(TextBuffer buffer) 127 { 128 auto __p = gtk_source_region_new((buffer is null) ? null : buffer.getTextBufferStruct()); 129 130 if(__p is null) 131 { 132 throw new ConstructionException("null returned by new"); 133 } 134 135 this(cast(GtkSourceRegion*) __p, true); 136 } 137 138 /** 139 * Adds @region_to_add to @region. 140 * 141 * @region_to_add is not modified. 142 * 143 * Params: 144 * regionToAdd = the #GtkSourceRegion to add to @region, or %NULL. 145 */ 146 public void addRegion(Region regionToAdd) 147 { 148 gtk_source_region_add_region(gtkSourceRegion, (regionToAdd is null) ? null : regionToAdd.getRegionStruct()); 149 } 150 151 /** 152 * Adds the subregion delimited by @_start and @_end to @region. 153 * 154 * Params: 155 * Start = the start of the subregion. 156 * End = the end of the subregion. 157 */ 158 public void addSubregion(TextIter Start, TextIter End) 159 { 160 gtk_source_region_add_subregion(gtkSourceRegion, (Start is null) ? null : Start.getTextIterStruct(), (End is null) ? null : End.getTextIterStruct()); 161 } 162 163 /** 164 * Gets the @start and @end bounds of the @region. 165 * 166 * Params: 167 * start = iterator to initialize with the start of @region, 168 * or %NULL. 169 * end = iterator to initialize with the end of @region, 170 * or %NULL. 171 * 172 * Returns: %TRUE if @start and @end have been set successfully (if non-%NULL), 173 * or %FALSE if the @region is empty. 174 */ 175 public bool getBounds(out TextIter start, out TextIter end) 176 { 177 GtkTextIter* outstart = sliceNew!GtkTextIter(); 178 GtkTextIter* outend = sliceNew!GtkTextIter(); 179 180 auto __p = gtk_source_region_get_bounds(gtkSourceRegion, outstart, outend) != 0; 181 182 start = ObjectG.getDObject!(TextIter)(outstart, true); 183 end = ObjectG.getDObject!(TextIter)(outend, true); 184 185 return __p; 186 } 187 188 /** 189 * Returns: the #GtkTextBuffer. 190 */ 191 public TextBuffer getBuffer() 192 { 193 auto __p = gtk_source_region_get_buffer(gtkSourceRegion); 194 195 if(__p is null) 196 { 197 return null; 198 } 199 200 return ObjectG.getDObject!(TextBuffer)(cast(GtkTextBuffer*) __p); 201 } 202 203 /** 204 * Initializes a [struct@RegionIter] to the first subregion of @region. 205 * 206 * If @region is empty, @iter will be initialized to the end iterator. 207 * 208 * Params: 209 * iter = iterator to initialize to the first subregion. 210 */ 211 public void getStartRegionIter(out RegionIter iter) 212 { 213 GtkSourceRegionIter* outiter = sliceNew!GtkSourceRegionIter(); 214 215 gtk_source_region_get_start_region_iter(gtkSourceRegion, outiter); 216 217 iter = ObjectG.getDObject!(RegionIter)(outiter, true); 218 } 219 220 /** 221 * Returns the intersection between @region1 and @region2. 222 * 223 * @region1 and @region2 are not modified. 224 * 225 * Params: 226 * region2 = a #GtkSourceRegion, or %NULL. 227 * 228 * Returns: the intersection as a #GtkSourceRegion 229 * object. 230 */ 231 public Region intersectRegion(Region region2) 232 { 233 auto __p = gtk_source_region_intersect_region(gtkSourceRegion, (region2 is null) ? null : region2.getRegionStruct()); 234 235 if(__p is null) 236 { 237 return null; 238 } 239 240 return ObjectG.getDObject!(Region)(cast(GtkSourceRegion*) __p, true); 241 } 242 243 /** 244 * Returns the intersection between @region and the subregion delimited by 245 * @_start and @_end. 246 * 247 * @region is not modified. 248 * 249 * Params: 250 * Start = the start of the subregion. 251 * End = the end of the subregion. 252 * 253 * Returns: the intersection as a new 254 * #GtkSourceRegion. 255 */ 256 public Region intersectSubregion(TextIter Start, TextIter End) 257 { 258 auto __p = gtk_source_region_intersect_subregion(gtkSourceRegion, (Start is null) ? null : Start.getTextIterStruct(), (End is null) ? null : End.getTextIterStruct()); 259 260 if(__p is null) 261 { 262 return null; 263 } 264 265 return ObjectG.getDObject!(Region)(cast(GtkSourceRegion*) __p, true); 266 } 267 268 /** 269 * Returns whether the @region is empty. 270 * 271 * A %NULL @region is considered empty. 272 * 273 * Returns: whether the @region is empty. 274 */ 275 public bool isEmpty() 276 { 277 return gtk_source_region_is_empty(gtkSourceRegion) != 0; 278 } 279 280 /** 281 * Subtracts @region_to_subtract from @region. 282 * 283 * @region_to_subtract is not modified. 284 * 285 * Params: 286 * regionToSubtract = the #GtkSourceRegion to subtract from 287 * @region, or %NULL. 288 */ 289 public void subtractRegion(Region regionToSubtract) 290 { 291 gtk_source_region_subtract_region(gtkSourceRegion, (regionToSubtract is null) ? null : regionToSubtract.getRegionStruct()); 292 } 293 294 /** 295 * Subtracts the subregion delimited by @_start and @_end from @region. 296 * 297 * Params: 298 * Start = the start of the subregion. 299 * End = the end of the subregion. 300 */ 301 public void subtractSubregion(TextIter Start, TextIter End) 302 { 303 gtk_source_region_subtract_subregion(gtkSourceRegion, (Start is null) ? null : Start.getTextIterStruct(), (End is null) ? null : End.getTextIterStruct()); 304 } 305 306 /** 307 * Gets a string represention of @region, for debugging purposes. 308 * 309 * The returned string contains the character offsets of the subregions. It 310 * doesn't include a newline character at the end of the string. 311 * 312 * Returns: a string represention of @region. Free 313 * with g_free() when no longer needed. 314 */ 315 public override string toString() 316 { 317 auto retStr = gtk_source_region_to_string(gtkSourceRegion); 318 319 scope(exit) Str.freeString(retStr); 320 return Str.toString(retStr); 321 } 322 }